package threadDemo;

/**
 * 观察测试线程的状态
 */
public class Test12 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                try {
                    System.out.println("休眠次数 = "+i);
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("/////");
        });

        // 观察线程状态
        Thread.State state = t.getState();
        System.out.println("没有start前状态 = "+state);

        t.start();
        state = t.getState();
        System.out.println("start后状态 = "+state);

        while (state != Thread.State.TERMINATED){// 只要状态不死亡就一致循环，输出状态
            Thread.sleep(100);
            state = t.getState();
            System.out.println("循环判断状态 = "+state);
        }
    }
}
